#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

int in[ 3 ][ 2001 ], co[ 3 ][ 2001 ];
int n, m;
vector<int> li[ 3 ][ 2001 ];

bool topsort( int p )
{
    int i, j, cnt = 0, t;
    queue<int> q;
    for ( i = 0; i < n * 2; i++ )
        if ( in[ p ][ i ] == 0 )
            q.push( i );
    while ( !q.empty( ) )
    {
        t = q.front( );
        q.pop( );
        co[ p ][ t ] = cnt++;
        for ( i = 0; i < li[ p ][ t ].size( ); i++ )
        {
            in[ p ][ li[ p ][ t ][ i ] ]--;
            if ( in[ p ][ li[ p ][ t ][ i ] ] == 0 )
                q.push( li[ p ][ t ][ i ] );
        }
    }
    return cnt == n * 2;
}

void work( )
{
    int i, j, u, v;
    char cmd[ 2 ];
    for ( i = 0; i < n * 2; i++ )
    {
        in[ 0 ][ i ] = in[ 1 ][ i ] = in[ 2 ][ i ] = 0;
        li[ 0 ][ i ].clear( );
        li[ 1 ][ i ].clear( );
        li[ 2 ][ i ].clear( );
    }
    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < 3; j++ )
        {
            li[ j ][ i ].push_back( i + n );
            in[ j ][ i + n ]++;
        }
    }
    for ( i = 0; i < m; i++ )
    {
        scanf("%s%d%d", cmd, &u, &v);
        u--; v--;
        if ( cmd[ 0 ] == 'I' )
        {
            for ( j = 0; j < 3; j++ )
            {
                li[ j ][ u ].push_back( v + n );
                li[ j ][ v ].push_back( u + n );
                in[ j ][ v + n ]++;
                in[ j ][ u + n ]++;
            }
        }
        if ( cmd[ 0 ] == 'X' )
        {
            li[ 0 ][ u + n ].push_back( v );
            in[ 0 ][ v ]++;
        }
        if ( cmd[ 0 ] == 'Y' )
        {
            li[ 1 ][ u + n ].push_back( v );
            in[ 1 ][ v ]++;
        }
        if ( cmd[ 0 ] == 'Z' )
        {
            li[ 2 ][ u + n ].push_back( v );
            in[ 2 ][ v ]++;
        }
    }
    if ( !topsort( 0 ) )
    {
        puts("IMPOSSIBLE");
        return ;
    }
    if ( !topsort( 1 ) )
    {
        puts("IMPOSSIBLE");
        return ;
    }
    if ( !topsort( 2 ) )
    {
        puts("IMPOSSIBLE");
        return ;
    }
    puts("POSSIBLE");
    for ( i = 0; i < n; i++ )
        printf("%d %d %d %d %d %d\n", co[ 0 ][ i ], co[ 1 ][ i ], co[ 2 ][ i ], co[ 0 ][ i + n ], co[ 1 ][ i + n ], co[ 2 ][ i + n ]);
}

int main( )
{
    int cas = 1;
    while ( scanf("%d%d" ,&n, &m) )
    {
        if ( n == 0 && m == 0 )
            break;
        printf("Case %d: ", cas++);
        work( );
        puts("");
    }
    return 0;
}
